
/**
 * 日志处理
 */
(function(hybrid){

    function arguments2Array(args, append){
        var arr = [];
        for (var i=0;i<args.length;i++){
            arr.push(args[i]);
        }
        if (append) arr.push(append);
        return arr;
    }

    hybrid.logger = {
        DEBUG: 'DEBUG',
        ERROR: 'ERROR',
        WARNING: 'WARNING',
        INFO: 'INFO',
        write: function(){
            var args = [];
            var level = this.INFO;
            for (var i=0;i<arguments.length;i++){
                var p = arguments[i];
                if(typeof p === 'object'){
                    p = JSON.stringify(p);
                }
                args.push(p);
            }
            if (args.length > 1 && typeof args[args.length - 1] === 'string'){
                level = args.pop();
            }
            hybrid.callAction('Core/logger', {
                level: level,
                args: args.join(' ')
            });
        },
        debug: function(){
            this.write.apply(this, arguments2Array(arguments, this.DEBUG));
        },
        error: function(){
            this.write.apply(this, arguments2Array(arguments, this.ERROR));
        },
        warning: function(){
            this.write.apply(this, arguments2Array(arguments, this.WARNING));
        },
        info: function(){
            this.write.apply(this, arguments2Array(arguments, this.INFO));
        }
    };

    hybrid.ready(function(){
        //hybrid.logger.info('add logger to window');
        window.logger = hybrid.logger;
        window.logger.log = hybrid.logger.info;
    });
})(Hybrid || {});
